package com.yuan.chatrobot.controlller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.yuan.chatrobot.tulingRobot.Changeless;
import com.yuan.chatrobot.tulingRobot.Robot;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 * @Author 小源同学
 * @Date 2021 12 16 23 27
 * @Describe Please describe the role of this class
 **/
//@WebServlet(name = "sent/chat", value = "/sent-chat")
//@WebServlet(name = "LoginServlet", urlPatterns = "/sent/chat")
public class SentMassageController {
    public static void main(String[] args) {
        Robot robot = new Robot();
        robot.setUrl("http://openapi.turingapi.com/openapi/api/v2");
        robot.setApiKey("b74da2cf0f8140ae8b8ab2f2539dc41b");
        robot.setUserId("123456789");
        String res = robot.Chat("讲个笑话");
        JSONArray objects = JSONUtil.parseArray(res);
//        System.out.println(JSONUtil.parseObj(JSONUtil.parseObj(jsonObject).get("values")));
        String str = "";
        ArrayList<JSONObject> arrayList = new ArrayList<>();
        for (Object jsonObject : objects) {
            arrayList.add((JSONObject) JSONUtil.parseObj(jsonObject).get("values"));
//            System.out.println(JSONUtil.parseObj(jsonObject).get("values"));
            //            str = str + "\n" + JSONUtil.parseObj(JSONUtil.parseObj(jsonObject).get("values")).get("text");
//            str = str + "\n" + JSONUtil.parseObj(JSONUtil.parseObj(jsonObject).get("values"));
        }
        System.out.println(arrayList);
    }
}
